package com.metagurukul.metaspace.dao;

import java.io.InputStream;

import java.sql.Connection;
import java.sql.SQLException;

import java.util.Scanner;

/**
 * @author Ritesh Gupta created date - 04 October 2012 Class ConnectionDAO to
 *         create and close connection to database
 */
public final class ConnectionDAO extends GenericConnection{

	/**
	 * make private Constructor for ConnectionDAO for stop making object
	 */
	
	private ConnectionDAO() {
	}

	/**to get a connection to database
	 * @return connection
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException {
		Scanner file = null;
		InputStream in = ConnectionDAO.class.getResourceAsStream("../../../../resources/database.txt");
		file = new Scanner(in);
		String driver = file.nextLine();  // driver name
		String connectionString = file.nextLine();  // connection string
		String userId = file.nextLine();  // userid
		String password = file.nextLine();  // password
		return generateConnection(driver, connectionString, userId, password);  // call function to make connection.
	}
}
